<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">知识库应用管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识库应用管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">知识库专题管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	 <div class="page-content">
        <!-- 知识分类s -->
       
	    
        <!-- 知识分类e -->
        <div class="row">
	        
	        
	        <div class="col-lg-4">
	            <div class="panel" style="height: 540px; overflow: auto;">
	                <div class="panel-heading">专题列表
	                	<p style="float: right;">
		                	<button  type="button" onclick="addSpecial(0)" class="btn btn-green btn-square" id="savejiedian">新建</button>&nbsp;
		                	<button  type="button" onclick="uploadeSpecial()" class="btn btn-green btn-square" id="savejiedian">编辑</button>&nbsp;
		                	<button  type="button"   class="btn btn-green btn-square"  onclick="deleteSpecial()" >删除</button>
	                	</p>
	                </div>
	                <div class="panel-body" >
	                	<ul id="tree" class="ztree" style="width:270px"; overflow:auto;"></ul>
	                </div>
	            </div>
	        </div>
	        
	        <div class="col-lg-8">
	        	<div class="row" >
					<div class="col-lg-3"
						style="width: 360px; float:left; margin-right:-20px; display:inline;">
						<label for="inputUsername" class="col-md-3 control-label" style="line-height: 30px;">资源类型
						</label>
						<div class="col-md-8">
							<div class="input-icon">
								<select id="chargeType" class="form-control" style="padding:3px 6px; height:30px;line-height:30px;">
									<option value="">--请选择--</option>
									<!-- <option value="0">按产品库计费</option>
									<option value="1">固定单价计费</option> -->
								</select>
							</div>
						</div>
					</div>
				
			
					<div class="col-lg-6">
						<div class="input-group input-group-sm mbs">
							<span class="input-group-btn">
								<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
				                    <!-- <option value="-1">筛选项&nbsp;<span class="caret"></span></option>
				                    <option value="classZh">资源类型</option> -->
				                    <option value="title">标题&nbsp;<span class="caret"></span></option>
		                    	</select>
		                   </span> 
		                    	<input id="text" type="text" placeholder="请输入关键词..." class="form-control" /><!-- <span
								class="input-group-btn"><button type="button"
									data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
							</span> -->
						</div>
					</div>
			</div>
			<div class="row  mbl" >
					<div class="col-lg-10" style="margin-top:20px">
						<button type="button" data-toggle="dropdown" onclick="get(1)" class="btn btn-success dropdown-toggle">精确搜索</button>
						&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button" data-toggle="dropdown" onclick="get(0)" class="btn btn-success dropdown-toggle">模糊搜索</button>
						&nbsp;&nbsp;&nbsp;&nbsp;
		               	&nbsp;&nbsp;&nbsp;&nbsp;
		               	<button class="btn btn-sm btn-primary" onclick="addSpecialData()">自定义添加
						</button>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<span id="dataCount"></span>
						
					</div>
			
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th >序号</th>
					<th >资源类型</th>
					<th >标题</th>
					<th >创建人</th>
					<th >创建时间</th>
					<th >状态</th>
					<!-- <th >创建日期</th>
					<th >个性签名</th> -->
					<th >可操作</th>
				</tr>
			</thead>
			<tbody id="findUser">
			</tbody>
		</table>
		<div id="dataNull" class="panel-body"
				style="height: 50px; line-height: 50px;" align="center">
		</div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	        </div>
        </div>
        
      </div>
                     
    <!--END CONTENT-->
    </div>  
<?} ?>
<script>
	var curr = 1;
	var id;
	var ztreeId;
	var parentname =1;
	var searchType;
	var ztreename;
	$(function() {
		
		initTree();
	});
	function get(flag) {
		searchType = flag;
		if (ztreeId != null && ztreeId != undefined) {
			querySpecialData(ztreeId,curr);
		}
	}
	function getlay() {
		return id;
	}
	
	function getztreename() {
		return ztreename;
	}
	function getztreeId() {
		return ztreeId;
	}
	
	function initTree() {
		$.ajax({
			type : "post",
			data : {},
			url : "applicationQuerySpecialManage.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
	//alert(JSON.stringify(data));
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		/* if (ztreeId != null && ztreeId != undefined) {
			var node = zTree.getNodeByParam("id", ztreeId);
			zTree.selectNode(node);
		} */
		
		zTree.expandNode(zTree.getNodes()[0], true);

	}
	
	function onClick(e, treeId, treeNode) {
		ztreeId = treeNode.id;	
		ztreename = treeNode.name;	
		//queryRoles(ztreeId);
		//queryAllUser(treeNode.id)
		$("#text").val("");
		$("#chargeType").val("");
		querySpecialData(ztreeId,curr);
		 if(treeNode.children==null || treeNode.children==undefined){
       		parentname=0;
       	 }else{
         	parentname=1;
        }
	}
	//编辑
	function uploadeSpecial() {
		if(ztreeId ==null){
			layer.msg('请选择要编辑专题！');
		}else{
			id = ztreeId;
			layer.open({
			type : 2,
			area : [ '800px', '660px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"编辑专题",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["application-special-manage-add.html", 'no'],
			yes : function(index,layer) {		
			 var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			  			  ztreename="根目录";
						  ztreeId=0;
			},
			cancel : function(index) {
			}
		});
		}
	}

	
	//删除
	function deleteSpecial(){
		if(ztreeId ==null){
			layer.msg('请选择要删除专题！');
		}else{
			if (parentname == 0) {
				if (confirm("是否确认删除！！")){
					$.ajax({
						type : "post",
						data : {
						"id":ztreeId
						},
						url : "specialManageDel.do",
						dataType : "json",
						beforeSend : function(XMLHttpRequest) {},
						success : function(data){
							if(data ==0){
								layer.msg('删除成功！');
							}else{
								layer.msg('有关联！无法删除');
							}
						             initTree();
			           		 },
					});
				
					//location.href="knowledgeEditDataRoleDeleteUserGroup.do?id="+ztreeId; 
				}
			} else {
				alert("有子分类不允许删除");
			}
		}
	}
	
	//加专题
	function addSpecial(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '800px', '660px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : false, //不固定
			title : '添加专题',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['保存 ', '关闭'],
			content : ["application-special-manage-add.html",'no'],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.save();
	                 ztreename="根目录";
					 ztreeId=0;
	         },
			cancel : function(index) {
			}
			
		});
	}
	
	
	
	
	//查询专题数据
	function querySpecialData(ztreeId,curr) {
		$.getJSON("./querySpecialDataList.do",
			{ 
				id:ztreeId,
				page : curr || 1,
				queryParams:$("#queryParams").val(),
        		text:$("#text").val(),
        		classZh:$("#chargeType").val(),
        		searchType:searchType
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				
				var dataRole = eval(res);
				var html='';
				var time=dataRole[0]["search"]["time"];
				var count=dataRole[0]["search"]["count"];
				$("#dataCount").html("共有 <label>"+count+"</label> 条记录");
				var data=dataRole[0]["search"]["data"];
				var dataRole2 = eval(data);
				var classList = dataRole[0]["classList"];
				var classZh = dataRole[0]["classZh"];
				var classHtml = "";
					classHtml += "<option value=''>--请选择--</option>";
				for(var j = 0;j <classList.length;j++) {
					if (classZh == classList[j]) {
						classHtml += "<option selected='selected' value='"+classList[j]+"'>"+classList[j]+"</option>";
					} else {
						classHtml += "<option value='"+classList[j]+"'>"+classList[j]+"</option>";
					}
					
				}
				$("#dataNull").html("");
				$("#chargeType").html(classHtml);
				
				$("#findUser").html("");
				var str = "";
				if (count > 0) {
					
					$("#page2").css("display","block");
					$("#dataNull").css("display","none");
					for(var i= 0; i< dataRole2.length;i++){
						str += "<tr><td>"
							+ (i + 1)
							+ "</td><td> <label id=>"
							+ dataRole2[i]["classZh"]
							+ "</label></td><td><label >"
							+ delMul(dataRole2[i]["title"]+'')
							+ "</label></td><td><label >"
							+ dataRole2[i]["create_user"]
							+ "</label></td><td><label >"
							+ getDate(dataRole2[i]["create_time"])
							+ "</label></td><td><label >";
						var status = "";
						if (dataRole2[i]["status"] == 0) {
							status = "未通过";
						} else {
							status = "已通过";
						}
						str +=status
							+ "</label></td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"window.open('show-edit-data-detail-update.html?id="+dataRole2[i]["id"]+"&classesEn="+dataRole2[i]["classEn"]+"&classesId="+dataRole2[i]["classes_id"]+"&curr="+curr+"&ztreeId="+ztreeId+"&searchType=1')\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"delData('"
							+ dataRole2[i]["id"]+"','"+dataRole2[i]["classEn"]+"','"+dataRole2[i]["classes_id"]
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"recall('"
							+ dataRole2[i]["id"]+"','"+dataRole2[i]["classEn"]+"','"+dataRole2[i]["classes_id"]
							+ "')\">"
							+ "撤回"
							+ "</button>&nbsp;" 
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"publish('"
							+ dataRole2[i]["id"]+"','"+dataRole2[i]["classEn"]
							+ "')\">"
							+ "重新发布"
							+ "</button>" 
							+ "</td></tr>";
					
						}
					$("#findUser").append(str);	

					laypage({
						cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
						pages :(Math.ceil(count/15)), //总页数
						skip : false, //是否开启跳页
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						curr : curr || 1,
						last : false,//(Math.ceil(dataRole[0]["search"]["count"]/$("#pageSize").val())),
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								querySpecialData(ztreeId,obj.curr);
								//var curr = obj.curr;
								curr = obj.curr;
							}
						}
					});

					
				} else {
					
					$("#page2").css("display","none");
					$("#dataNull").css("display","block");
					$("#dataNull").html("<span class='subtitle' style='font-size: 15px;'>数据为空!</span>");
				}
				
			});
		
	
	}
	
	//删除单条数据
	function delData(id,classEn,classesId) { 
		
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "applicationSpecialDataDeteleMethod.do",
				dataType : "json",
				data :{
						"id":id,
						"ztreeId":ztreeId,
						"classesEn":classEn,
						"classesId":classesId
				},
				beforeSend : function(XMLHttpRequest) {},
				success : function(res) {
					if(res[0].data == '0'){
						layer.msg('删除成功！');
						querySpecialData(ztreeId,curr);
					}else{
						layer.msg('删除失败！');
					}
				},
				error:function(){
					alert("编辑失败");
				}
			});
		}
	}
	
	
	/* //删除单条数据
	function delData(id,classEn,classesId) { 
		
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "knowledgeEditDataDetailDeteleMethod.do",
				dataType : "json",
				data :{
						"id":id,
						"classesEn":classEn,
						"classesId":classesId
				},
				beforeSend : function(XMLHttpRequest) {},
				success : function(res) {
					if(res[0].data == '0'){
						layer.msg('删除成功！');
						querySpecialData(ztreeId,curr);
					}else{
						layer.msg('删除失败！');
					}
				},
				error:function(){
					alert("编辑失败");
				}
			});
		}
	}
 */
 
 	//撤回
 	function recall(id,classEn,classesId) {
 		if (confirm("是否确认撤回！！")){
			$.ajax({
				type : "post",
				url : "applicationSpecialDataRecall.do",
				dataType : "json",
				data :{
						"id":id,
						"classesEn":classEn,
						"classesId":classesId
				},
				beforeSend : function(XMLHttpRequest) {},
				success : function(res) {
					if(res[0].data == '0'){
						layer.msg('撤回成功！');
						querySpecialData(ztreeId,curr);
					}else{
						layer.msg('撤回失败！');
					}
				},
				error:function(){
					alert("编辑失败");
				}
			});
		}	
 	}
 
	//单条数据发布
	function publish(publishId,classEn){
		if (confirm("是否确认发布！！")){
			
			$.ajax({
					type : "post",
					url : "knowledgeEditDataPublish.do",
					dataType : "json",
					data:{
						"classesEn":classEn,
						"id":publishId
					},
					beforeSend : function(XMLHttpRequest) {},
					success:function(res){
						if(res == 'yes'){
							 layer.msg('发布成功！');
							 //querySpecialData(ztreeId,curr);
						}else{
							layer.msg('发布失败！');
						}
					},
					error:function(){
						alert("发布失败");
					}
		
			});
		}
	}

	function queryDetails(id,classesId){
		
		layer.open({
			type: 2,
			title: '详情',
			shadeClose: true,
			btn : [ '关闭' ],
			area: ['800px', '600px'],
			content: "querychoicerrelevance?classesId="+classesId+"&id="+id,//iframe的url
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
						
			},
			cancel : function(index) {
			}
		
		});
	}

	//自定义专题库数据
	function addSpecialData() {
		if (ztreeId != null && ztreeId != undefined) {
		
			layer.open({
				type : 2,
				area : [ '966px', '660px' ],
			    scrollbar: false,
			    shadeClose: true,
				fix : false, //不固定
				title : '添加',
				//maxmin : true,  
				skin: 'layui-layer-rim', //加上边框
	    	    btn: ['保存 ', '关闭'],
				content : ["application-special-data-queryspecial.html",'no'],
				yes: function(index,layer){
		                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
		                 iframeWin.save();
		         },
				cancel : function(index) {
				}
				
			});
		
		} else {
			alert("请先选择专题！");
		}
	}



	//字符串转时间格式  
	function getDate(strDate) {
		var time='';
		for(var key in strDate){
			var text = new Date(strDate[key]["time"]).format("yyyy-MM-dd hh:mm:ss");
			time+=text+"  ";
		}
		
		return time;
	} 
	
	//日期格式化
	Date.prototype.format = function (fmt) { //author: meizz 
	    var o = {
	        "M+": this.getMonth() + 1, //月份 
	        "d+": this.getDate(), //日 
	        "h+": this.getHours(), //小时 
	        "m+": this.getMinutes(), //分 
	        "s+": this.getSeconds(), //秒 
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
	        "S": this.getMilliseconds() //毫秒 
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	};

	//删除多语种前面的英文
	function delMul(str){
		var temp=str;
		if(temp.indexOf("|")>-1){
			temp=temp.substr(temp.indexOf("|")+1,temp.length);
		}else{
			temp=temp;
		}
		return temp;
	}
</script>